<?php
/**************************************************************************
 *
 *   Copyright 2010 American Public Media Group
 *
 *   This file is part of AIR2.
 *
 *   AIR2 is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   AIR2 is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with AIR2.  If not, see <http://www.gnu.org/licenses/>.
 *
 *************************************************************************/

/**
 * Tag
 *
 * A generic resource-tag in AIR2
 *
 * @property integer $tag_tm_id
 * @property integer $tag_xid
 * @property string $tag_ref_type
 * @property integer $tag_cre_user
 * @property integer $tag_upd_user
 * @property timestamp $tag_cre_dtim
 * @property timestamp $tag_upd_dtim
 * @property TagMaster $TagMaster
 * @author rcavis
 * @package default
 */
class Tag extends AIR2_Record {
    /* code_master values */
    public static $TYPE_INQUIRY = 'I';
    public static $TYPE_PROJECT = 'P';
    public static $TYPE_SOURCE = 'S';
    public static $TYPE_RESPONSE_SET = 'R';

    /**
     * Set the table columns
     */
    public function setTableDefinition() {
        $this->setTableName('tag');
        $this->hasColumn('tag_tm_id', 'integer', 4, array(
                'primary' => true,
            ));
        $this->hasColumn('tag_xid', 'integer', 4, array(
                'primary' => true,
            ));
        $this->hasColumn('tag_ref_type', 'string', 1, array(
                'primary' => true,
            ));
        $this->hasColumn('tag_cre_user', 'integer', 4, array(
                'notnull' => true,
            ));
        $this->hasColumn('tag_upd_user', 'integer', 4, array(

            ));
        $this->hasColumn('tag_cre_dtim', 'timestamp', null, array(
                'notnull' => true,
            ));
        $this->hasColumn('tag_upd_dtim', 'timestamp', null, array(

            ));

        parent::setTableDefinition();

        // setup mapping for tag_xid
        $this->setSubclasses(array(
                'TagInquiry'  => array('tag_ref_type' => 'I'),
                'TagProject'  => array('tag_ref_type' => 'P'),
                'TagSource'   => array('tag_ref_type' => 'S'),
                'TagResponseSet' => array('tag_ref_type' => 'R'),
            ));
    }


    /**
     * Set table relations
     */
    public function setUp() {
        parent::setUp();
        $this->hasOne('TagMaster', array(
                'local' => 'tag_tm_id',
                'foreign' => 'tm_id',
                'onDelete' => 'CASCADE',
            ));
    }


}
